package 比赛匹配问题.src.main;

public class Main {
    public static int solution(int n) {
        // write code here
        int times_num = 0;
        int team_num = n;

        if (n == 1) return 0;

        while (team_num > 1) {
            if (isEven(team_num)) {
                times_num += team_num / 2;
                team_num = team_num / 2;


            } else {
                times_num += (team_num - 1) / 2;
                team_num = (team_num - 1) / 2 + 1;


            }

        }

        return times_num;
    }

    public static boolean isEven(int n) {
        return n % 2 == 0;
    }

    public static void main(String[] args) {
        System.out.println(solution(7));
        System.out.println(solution(14));
        System.out.println(solution(1));

         System.out.println(solution(7) == 6);
         System.out.println(solution(14) == 13);
         System.out.println(solution(1) == 0);
    }
}